function [x,fval,residual,exitflag,output]=optim_fitsubphase(Param,xdata,ydata,yerr,LB,UB)
options=optimset('MaxIter',500,'TolFun',1e-8,'Display','iter','TolX',1e-8,'MaxFunEvals',2000);
[x,fval,residual,exitflag,output]=lsqcurvefit(@nestedfun,Param,xdata,(ydata./yerr),LB,UB,options);
    function y=nestedfun(Param,xdata)
        
        C=Param(1);
        qc=Param(2);
        bkg=Param(3);
        
        qz=xdata;
        Eng=8.05;
        lambda=1.54;
        Attl=1008e4; % Attenuation length in unit of Angstrom for water @ 8.05 keV
        mu=1/Attl;
        
        beta=mu*lambda/4/pi;
      
        t=Transmission(qz,qc,beta,lambda);
        y=bkg+C*t.*fitsubphase(qz,qc,Eng,Attl);
        y=(y./yerr);
    end
end
